#ifndef GRABBER_H_
#define GRABBER_H_

#include <list>
#include "grabable.h"

class Grabber{
	private:
		Rectangle position;
		std::list<Grabable*> grabables;
		Grabable* grabbed;

	public:
		Grabber(Rectangle position){
			this->position = position;
			this->grabbed=NULL;
		}

		~Grabber(){}

		void addGrabable(Grabable* grabable){
			grabables.push_back(grabable);
		}

		void removeGrabable(Grabable* grabable){
			grabables.remove(grabable);
		}

		Grabable* getGrabbed(){
			return grabbed;
		}

		Grabable* release(){
			Grabable* ret = this->grabbed;
			this->grabbed = NULL;
			return ret;
		}

		void movePosition(float dx,float dy){
			this->position.translate(dx,dy);
		}

		bool grab(){
			for(std::list<Grabable*>::iterator it=grabables.begin();it!=grabables.end();++it){
				if(this->position.intersect((*it)->getGrabZone())){
					this->grabbed = *it;
					return true;
				}
			}
			return false;
		}
};

#endif /* GRABBER_H_ */
